package com.hcb.tonguetiphealth.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hcb.tonguetiphealth.model.Ordered;
import com.hcb.tonguetiphealth.view.R;

public class OrderedListAdapter extends BaseAdapter {

	private Context mContext;
	private List<Ordered> mList;
	private LayoutInflater vi;
	
	public OrderedListAdapter(Context context,List<Ordered> list) {
		mContext = context;
		mList = list;
	}
	
	public int getCount() {
		if(mList == null) {
			return 0;
		}
		return mList.size();
	}
	
	public Object getItem(int position) {
		if(mList == null) {
			return null;
		} else {
			return mList.get(position);
		}
	}
	
	public long getItemId(int position) {
		return position;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {

		View view;
		
		if(convertView == null) {
			vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = (LinearLayout) vi.inflate(R.layout.homepage_personal_ordered_list_item, null);
		} else {
			view = convertView;
		}
		FillDataIntoView(view, position);
		
		return view;
	}
	
	private void FillDataIntoView(View view, final int position) {
		final Ordered ordered = mList.get(position);

		TextView tv_remark = (TextView)view.findViewById(R.id.homepage_ordered_remark);
		TextView tv_time = (TextView)view.findViewById(R.id.homepage_ordered_time);
		TextView tv_price = (TextView)view.findViewById(R.id.homepage_ordered_price);

		tv_remark.setText(ordered.getRemark());
		tv_time.setText(ordered.getTime());
		tv_price.setText(ordered.getPrice() + " 元");
	}

	@Override
	public boolean isEnabled(int position) {
		// TODO Auto-generated method stub
		//return super.isEnabled(position);
		return false;
	}
}
